!< END interface definition for Lib_VTK_IO.
module Lib_VTK_IO_END
!-----------------------------------------------------------------------------------------------------------------------------------
!< END interface definition for Lib_VTK_IO.
!-----------------------------------------------------------------------------------------------------------------------------------
use Lib_VTK_IO_Back_End ! Lib_VTK_IO back end module.
use penf                ! Portability environment.
!-----------------------------------------------------------------------------------------------------------------------------------

!-----------------------------------------------------------------------------------------------------------------------------------
implicit none
private
public :: VTK_END
!-----------------------------------------------------------------------------------------------------------------------------------
contains
  function VTK_END(cf) result(E_IO)
  !---------------------------------------------------------------------------------------------------------------------------------
  !< Function for finalizing the VTK-XML file.
  !<
  !<### Usage
  !<```fortran
  !< E_IO = VTK_END()
  !<```
  !---------------------------------------------------------------------------------------------------------------------------------
  implicit none
  integer(I4P), intent(INOUT), optional:: cf   !< Current file index (for concurrent files IO).
  integer(I4P)::                          E_IO !< Input/Output inquiring flag: $0$ if IO is done, $> 0$ if IO is not done.
  integer(I4P)::                          rf   !< Real file index.
  !---------------------------------------------------------------------------------------------------------------------------------

  !---------------------------------------------------------------------------------------------------------------------------------
  E_IO = -1_I4P
  rf = f
  if (present(cf)) then
    rf = cf ; f = cf
  endif
  close(unit=vtk(rf)%u,iostat=E_IO)
  call vtk_update(act='remove',cf=rf,Nvtk=Nvtk,vtk=vtk)
  f = rf
  if (present(cf)) cf = rf
  return
  !---------------------------------------------------------------------------------------------------------------------------------
  endfunction VTK_END
endmodule Lib_VTK_IO_END
